using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using UnityEditorInternal.Profiling.Memory.Experimental;
using UnityEngine;

[Serializable]
public class AgentGridDictionary : SerializedDictionary<Tuple<int,int,int>, List<GameObject>> { }
public class AgentManager : MonoBehaviour
{public static AgentManager instance;

    public float maxSpeed;
    public float maxSteeringForce;
    public float responseRadius;

    public float attractWeight;
    public float rejectWeight;
    public float alignWeight;
    public float targetWeight;

    public int maxcnt;
    public GameObject[] AllAgents;
    public AgentGridDictionary agentGridDictionary;
    public int GridRadius;
    public GameObject feb;

    private void Awake()
    {
        instance = this;
    }
    void Start()
    {
        AllAgents = new GameObject[maxcnt];
        agentGridDictionary=new AgentGridDictionary();
        for (int i = 0; i < maxcnt; i++)
        {
            float randomX = UnityEngine.Random.Range(-20f, 20f);
            float randomY = UnityEngine.Random.Range(-20f, 20f);
            float randomZ = UnityEngine.Random.Range(-20f, 20f);

            Vector3 randomVector = new Vector3(randomX, randomY, randomZ);
            AllAgents[i]= Instantiate(feb, randomVector,Quaternion.identity);
        }
    }
    void Update()
    {
        
    }
    public Tuple<int, int, int> UpdateGridKey(Vector3 Pos)
    {
        int x, y, z;
        x = (int)(Pos.x / GridRadius);
        y = (int)(Pos.y / GridRadius);
        z = (int)(Pos.z / GridRadius);

        Tuple<int, int, int> key=new Tuple<int, int, int>(x,y,z);
        return key;
    }
    public void addAgent(Tuple<int, int, int> key,GameObject theagent)
    {
        if (!agentGridDictionary.ContainsKey(key))
        {
            agentGridDictionary.Add(key, new List<GameObject>());
        }
        agentGridDictionary[key].Add(theagent);
        
    }
    public void removeAgent(Tuple<int, int, int> key, GameObject theagent)
    {
        if (!agentGridDictionary.ContainsKey(key))
        {
            agentGridDictionary.Add(key, new List<GameObject>());
        }
        agentGridDictionary[key].Remove(theagent);
    }


    public GameObject[] GetAgents()
    {
        return AllAgents;
    }
}
